package com.yang.yangCommand;

import com.yang.YangVip;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;

public class VipController implements Listener, CommandExecutor {

    private static YangVip yangVip;

    public VipController(YangVip yangVip) {
        this.yangVip = yangVip;
    }

    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {
        Player player = event.getPlayer();
        String title = ChatColor.RED + "[测试]" + ChatColor.RESET; // 设置整个称号为红色

        // 修改聊天信息格式，将称号添加到聊天信息前面
        String formattedMessage = String.format("%s %s: %s ", title, player.getName(), event.getMessage());

        // 设置修改后的聊天信息
        event.setFormat(formattedMessage);
    }

//    @EventHandler
//    public void onTabComplete(TabCompleteEvent event) {
//        if (event.getSender() instanceof Player) {
//            Player player = (Player) event.getSender();
//            String title = getTitleForPlayer(player); // 获取玩家的称号
//            String title = "测试"; // 获取玩家的称号

            // 修改玩家列表中的显示信息
//            List<String> suggestions = event.getSuggestions();
//            for (int i = 0; i < suggestions.size(); i++) {
//                suggestions.set(i, title + " " + suggestions.get(i));
//            }
//        }
//    }



    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        // 处理命令
//        if (!label.equalsIgnoreCase("yangVip")) {
//            return true;
//        }
        if (label.equalsIgnoreCase("yangVipGive")) {
            // 处理 give 子命令的逻辑
        } else if (label.equalsIgnoreCase("yangVipSave")) {
            // 处理 save 子命令的逻辑
        } else if (label.equalsIgnoreCase("yangVipRemove")) {
            // 处理 remove 子命令的逻辑
        }else{
            return true;
        }
        if (args.length == 0) {
            sender.sendMessage("§a§lYangVip §7§lV" + yangVip.getDescription().getVersion());
            sender.sendMessage("§7§l作者: §aZhaoYang");
            return true;
        }
        // 判断是否为玩家
        if (sender instanceof Player) {
            yangVip.getLogger().info(ChatColor.RED + String.valueOf(args[3].equals("")));
            yangVip.getLogger().info(ChatColor.GREEN + String.valueOf(args[3].equals("null")));
            yangVip.getLogger().info(ChatColor.BLUE + String.valueOf(args[3].equals(null)));
            // 拿到玩家名字
            String userName = !args[0].equals("null") ? args[0] : "null";
            // 设置VIP等级
            String vipLevel = !args[1].equals("null") ? args[1] : "null";
            // 设置天数
            String days = !args[2].equals("null") ? args[2] : "null";
            // 设置称号
            String title = !args[3].equals("null") ? args[3] : "null";
        } else {

        }
        return true;
    }
}
